package com.hh;


import java.util.List;

import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.hh.entity.User;
import com.hh.service.IUserService;

public class XmlCrudDemo {
	@Test
	public void addUserTest() {
		ClassPathXmlApplicationContext context=new ClassPathXmlApplicationContext("xmlDemo.xml");
		IUserService userService=(IUserService)context.getBean("userService");
		User user=(User) context.getBean("temo");
		userService.saveUser(user);
		context.close();
	}
	
	@Test
	public void updateUserTest() {
		ClassPathXmlApplicationContext context=new ClassPathXmlApplicationContext("xmlDemo.xml");
		IUserService userService=(IUserService)context.getBean("userService");
		User user=(User) context.getBean("dema");
		userService.updateUser(user);
		context.close();
	}
	
	@Test
	public void findUserTest() {
		ClassPathXmlApplicationContext context=new ClassPathXmlApplicationContext("xmlDemo.xml");
		IUserService userService=(IUserService)context.getBean("userService");
		User user=userService.findUser(12);
		System.out.println(user);
		context.close();
	}
	
	@Test
	public void selectUserTest() {
		ClassPathXmlApplicationContext context=new ClassPathXmlApplicationContext("xmlDemo.xml");
		IUserService userService=(IUserService)context.getBean("userService");
		String name="%ʯ%";
		List<User> list=userService.selectUser(name);
		System.out.println(list);
		context.close();
	}
	
	@Test
	public void deleteUserTest() {
		ClassPathXmlApplicationContext context=new ClassPathXmlApplicationContext("xmlDemo.xml");
		IUserService userService=(IUserService)context.getBean("userService");
		userService.deleteUser(10);
		context.close();
	}
	
}
